package me.zhengjie.server.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import me.zhengjie.dao.*;
import me.zhengjie.dao.dto.ContainerQueryCriteria;
import me.zhengjie.mapper.ContainerMapper;
import me.zhengjie.mapper.StoreLocalMapper;
import me.zhengjie.server.EndContainerService;
import me.zhengjie.server.WcsToSendWmsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
@AllArgsConstructor
public class WcsToSendWmsServiceImpl implements WcsToSendWmsService {

    @Resource
    private StoreLocalMapper storeLocalMapper;
    private final EndContainerService endContainerService;

    @Override
    public EmptyContainerDao emptyContainer(String station) {
        EmptyContainerDao dao = new EmptyContainerDao();
        ContainerQueryCriteria criteria = new ContainerQueryCriteria();
        List<StoreLocalDao> all = storeLocalMapper.getList(criteria);
        if (all.isEmpty()) {
            throw new RuntimeException("暂时无空容器！");
        }
        List<StoreLocalDao> localDaoList = all.stream().filter(e -> e.getContainerCode() != null).collect(Collectors.toList());
        if (localDaoList.isEmpty()) {
            throw new RuntimeException("暂时无空容器！");
        }
        StoreLocalDao storeLocalDao = localDaoList.get(0);
        dao.setContainerCode(storeLocalDao.getContainerCode());
        dao.setStorageCode(storeLocalDao.getId());
        if (dao.getContainerCode()==null){
            throw new RuntimeException("暂时无空容器！");
        }
        return dao;
    }

    @Override
    public PalletCodeDao palletCode(String palletCode) {
        PalletCodeDao dao = new PalletCodeDao();
        EndContainerDao endContainerDao = endContainerService.getOne(new LambdaQueryWrapper<EndContainerDao>().
                eq(EndContainerDao::getEndStore, palletCode).eq(EndContainerDao::getFloor, "1F"));
        dao.setContainerCode(endContainerDao.getContainerCode());
        return dao;
    }

    @Override
    public Object pickPlace(PickPlaceDao placeDao) {
        return null;
    }
}
